<?php

declare(strict_types=1);

namespace App\Controller\Am;
/**
 * 微信用户管理控制层
 * @Author abell
 * @DateTime 2020-06-08
 */

use App\Controller\AbstractController;
use App\Constants\ErrorCode;
// 注解路由
use App\Utils\ApiUtils;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;


class MongodbInitial extends AbstractController
{
    /**
     * mongodb 自动创建table数据
     * Abell 2020/5/19
     * @RequestMapping(path="/am/mongodb_initial/install", methods="get")
     */
    public function install(){
        //创建小程序用户表  pc_wxuser
        $insert = [
            'openid' => 'ogtzs4bmnorPZFkdXiFgo0IjADX1',
            'nickname' => '呢称',
            "pid"=>"openid",
            "devicecode"=>"设备号",
            "avatarurl"=>"https://avatar.csdnimg.cn/2/1/A/3_gjalj10.jpg",
            "gender"=>1,
            "country"=> "中国",
            "province"=> "江苏省",
            "city"=> "无锡市",
            "language"=> "zh",
            "add_time"=> 1589019140,
            "mobile"=> 15512345678,
            "update_time"=> 1589019140,
            "haspay"=> 1,
            "statue"=> 0,
            "hasadd"=> 1
        ];
        $user_result = $this->mongoDbClient->insert('pc_wxuser',$insert);
        // 创建 小程序活动通知表  pc_wxnotice
        $wxnotice_insert =[
            'title' => '活动标题',
            'content' => '活动内容',
            "img"=>"https://avatar.csdnimg.cn/2/1/A/3_gjalj10.jpg",
            "type"=>1, //活动类型1 外链 2 文本编辑器 3 无
            "is_del"=> 1, // 是否删除 默认1,删除2
            "start_time"=> 1589019140,
            "end_time"=> 1589019140,
            "add_time"=> 1589019140,
            "update_time"=> 1589019140,
        ];
        $wxnotice_result = $this->mongoDbClient->insert('pc_wxnotice',$wxnotice_insert);
        //  小程序活动通知类型  pc_wxnoticetype
        $wxnoticetype_insert = [
            'title' => '通知类型标题',
            "add_time"=> 1589019140,
            "update_time"=> 1589019140,
        ];
        $wxnoticetype_result = $this->mongoDbClient->insert('pc_wxnoticetype',$wxnoticetype_insert);
        //问题反馈表   pc_wxservice
        $wxservice_insert = [
            'openid' => 'ogtzs4bmnorPZFkdXiFgo0IjADX1',
            'title' => '问题反馈提交标题',
            "detail"=>"问题反馈提交详情",
            "mobile"=>"联系方式",
            'statue'=>0, // 用户状态 0 未处理 1 正在处理 2 已经处理 3 情况待定
            'reply' => '后台回复客户',
            'type'  => 1 //问题反馈类型
        ];
        $wxservice_result = $this->mongoDbClient->insert('pc_wxservice',$wxservice_insert);
        // 问题反馈类型表 pc_wxservicetype
        $wxservicetype_insert = [
            'title' => '问题反馈类型标题',
            "add_time"=> 1589019140,
            "update_time"=> 1589019140,
            'type'  => 1,
            'is_del'   => 1 // 是否删除 默认1,删除2
        ];
        $wxservicetype_result = $this->mongoDbClient->insert('pc_wxservicetype',$wxservicetype_insert);
        // 小程序用户签到表 pc_wxsign
        $wxsign_insert = [
            'openid' => 'ogtzs4bmnorPZFkdXiFgo0IjADX1',
            "add_time"=> 1589019140,
            "update_time"=> 1589019140
        ];
        $wxsign_result = $this->mongoDbClient->insert('pc_wxsign',$wxsign_insert);
        // 小程序访问记录 pc_wxvisit
        $wxvisit_insert = [
            'openid' => 'ogtzs4bmnorPZFkdXiFgo0IjADX1',
            'pid' => 'fadfad', // 是否是总统计id 0 基础统计 1 子页面统计
            "type_explain"=>"/home/hello", //访问页面路径
            "watch"=>1, //查看次数
            "add_time"=> 1589019140,
            "update_time"=> 1589019140
        ];
        $wxvisit_result = $this->mongoDbClient->insert('pc_wxvisit',$wxvisit_insert);
        // 微信后台访问记录  pc_wxdata
        $wxdata_insert = [
            'visit_total' => 11, // 累计用户数
            'share_pv' => 1,  // 转发次数
            'share_uv' => 1,  // 转发人数
            'daily_retain' => 'fasdfadsfa', // 日留存数据json
            "add_time"=> 1589019140
        ];
        $wxdata_result = $this->mongoDbClient->insert('pc_wxdata',$wxdata_insert);
        return $this->response->json(ApiUtils::send(0,'ok',[
            'pc_wxuser' => $user_result, 'pc_wxnotice' => $wxnotice_result ,'pc_wxnoticetype' => $wxnoticetype_result,
            'pc_wxservice' => $wxservice_result,'pc_wxservicetype' =>$wxservicetype_result,
            'pc_wxsign' => $wxsign_result,'pc_wxvisit'=>$wxvisit_result,'pc_wxdata'=>$wxdata_result
        ],1));
    }


}
